package com.teamblueplus.comicmaker;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.teamblueplus.R;
import com.teamblueplus.websearch.GoogleImageBean;
import com.teamblueplus.websearch.ImageLoader;

/**
 * GridView for viewing images in a grid
 * 
 * @author qui
 * 
 */
public class DefaultObjectGridViewAdapter extends BaseAdapter {
	private Context context;
	// private Activity activity;
	private ArrayList<String> listImages;
	private static LayoutInflater inflater = null;
	public ImageLoader imageLoader;

	public DefaultObjectGridViewAdapter(Context con,
			ArrayList<String> listImages) {

		this.context = con;
		this.listImages = listImages;
		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public static class ViewHolder {
		public ImageView imgViewImage;
		public TextView txtViewTitle;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;
		ViewHolder holder;
		if (convertView == null) {
			vi = inflater.inflate(R.layout.gridview_row, null);
			holder = new ViewHolder();

			holder.imgViewImage = (ImageView) vi
					.findViewById(R.id.grid_item_image);
			// holder.txtViewTitle=(TextView)vi.findViewById(R.id.textView1);

			vi.setTag(holder);
		} else
			holder = (ViewHolder) vi.getTag();

		String path = listImages.get(position);
		Bitmap bitmap = BitmapFactory.decodeFile(path);
		holder.imgViewImage.setImageBitmap(bitmap);

		// holder.txtViewTitle.setText(Html.fromHtml(imageBean.getTitle()));
		return vi;

	}

	public int getCount() {
		return listImages.size();
	}

	public Object getItem(int position) {

		return listImages.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

}
